package com.jcfy.project.module.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jcfy.framework.aspectj.lang.annotation.Log;
import com.jcfy.framework.aspectj.lang.enums.BusinessType;
import com.jcfy.project.module.domain.TAddress;
import com.jcfy.project.module.service.ITAddressService;
import com.jcfy.framework.web.controller.BaseController;
import com.jcfy.framework.web.domain.AjaxResult;
import com.jcfy.common.utils.poi.ExcelUtil;
import com.jcfy.framework.web.page.TableDataInfo;

/**
 * 地址Controller
 *
 * @author jiangfeng
 * @date 2020-08-05
 */
@RestController
@RequestMapping("/module/address" )
public class TAddressController extends BaseController {
    @Autowired
    private ITAddressService tAddressService;

    /**
     * 查询地址列表
     */
    @PreAuthorize("@ss.hasPermi('module:address:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(TAddress tAddress) {
        startPage();
        List<TAddress> list = tAddressService.selectTAddressList(tAddress);
        return getDataTable(list);
    }

    /**
     * 导出地址列表
     */
    @PreAuthorize("@ss.hasPermi('module:address:export')" )
    @Log(title = "地址" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TAddress tAddress) {
        List<TAddress> list = tAddressService.selectTAddressList(tAddress);
        ExcelUtil<TAddress> util = new ExcelUtil<TAddress>(TAddress. class);
        return util.exportExcel(list, "address" );
    }

    /**
     * 获取地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:address:query')" )
    @GetMapping(value = "/{addressId}" )
    public AjaxResult getInfo(@PathVariable("addressId" ) Long addressId) {
        return AjaxResult.success(tAddressService.selectTAddressById(addressId));
    }

    /**
     * 新增地址
     */
    @PreAuthorize("@ss.hasPermi('module:address:add')" )
    @Log(title = "地址" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TAddress tAddress) {
        return toAjax(tAddressService.insertTAddress(tAddress));
    }

    /**
     * 修改地址
     */
    @PreAuthorize("@ss.hasPermi('module:address:edit')" )
    @Log(title = "地址" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TAddress tAddress) {
        return toAjax(tAddressService.updateTAddress(tAddress));
    }

    /**
     * 删除地址
     */
    @PreAuthorize("@ss.hasPermi('module:address:remove')" )
    @Log(title = "地址" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{addressIds}" )
    public AjaxResult remove(@PathVariable Long[] addressIds) {
        return toAjax(tAddressService.deleteTAddressByIds(addressIds));
    }
}
